package com.css.dzj.dzjdzqs.modules.apaction.aprandomplan.service.impl;

import com.alibaba.fastjson.JSON;
import com.css.dzj.dzjdzqs.common.util.HttpClientUtil;
import com.css.dzj.dzjdzqs.modules.apaction.aprandomplan.entity.JgZtkJgxnSsjygkNdjhsjEntity;
import com.css.dzj.dzjdzqs.modules.apaction.aprandomplan.entity.JgZtkJgxnSsjygkSpotCheckEntity;
import com.css.dzj.dzjdzqs.modules.apaction.aprandomplan.mapper.JgZtkJgxnSsjygkNdjhsjMapper;
import com.css.dzj.dzjdzqs.modules.apaction.aprandomplan.mapper.JgZtkJgxnSsjygkSpotCheckMapper;
import com.css.dzj.dzjdzqs.modules.apaction.aprandomplan.service.JgZtkJgxnSsjygkNdjhsjService;
import com.css.dzj.dzjdzqs.modules.apaction.aprandomplan.service.JgZtkJgxnSsjygkSpotCheckService;
import com.css.dzj.dzjdzqs.modules.apaction.aprandomplan.vo.ApDeptExtractInfoEntityVo;
import com.css.dzj.dzjdzqs.modules.apaction.aprandomplan.vo.ApUnitEntityVo;
import com.css.dzj.dzjdzqs.modules.datafromzfjg.service.JgLhjgJcdxService;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class JgZtkJgxnSsjygkSpotCheckServiceImpl implements JgZtkJgxnSsjygkSpotCheckService {
    @Autowired
    private JgLhjgJcdxService jcdxService;
    @Value("${AP_URL}")
    private String apUrl;
    @Autowired
    private JPAQueryFactory jpaQueryFactory;
    @Autowired
    private JgZtkJgxnSsjygkSpotCheckMapper jgZtkJgxnSsjygkSpotCheckMapper;

    //获取来自安评备案信息数据
    @Override
    @Transactional
    public void addSsjygkSpotCheck()  {
        try {
            String list = HttpClientUtil.doGet(apUrl + "/apunit/queryAllApUnitMsg");
            List<ApUnitEntityVo> results = JSON.parseArray(list, ApUnitEntityVo.class);
            for (ApUnitEntityVo result : results) {
                JgZtkJgxnSsjygkSpotCheckEntity jgZtkJgxnSsjygkSpotCheckEntity = new JgZtkJgxnSsjygkSpotCheckEntity();
                jgZtkJgxnSsjygkSpotCheckEntity.setPlanId(result.getId());
                jgZtkJgxnSsjygkSpotCheckEntity.setCheckObjectName(result.getUnitName());
                jgZtkJgxnSsjygkSpotCheckEntity.setCheckObjectId("");
                jgZtkJgxnSsjygkSpotCheckEntity.setEnterpriseCreditCode(result.getUniscid());
                jgZtkJgxnSsjygkSpotCheckMapper.save(jgZtkJgxnSsjygkSpotCheckEntity);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
